from selenium.webdriver.common.by import By
from time import sleep

class LoginPage():
    def __init__(self,driver):
        self.driver = driver
    # 登录成功
    def login(self,username,password):
        # 输入用户名
        self.driver.find_element(By.ID, "username").send_keys(username)
        # 输入密码
        self.driver.find_element(By.ID, "password").send_keys(password)
        # 点击登录
        self.driver.find_element(By.ID, "login_btn").click()
        sleep(1)


    def loginNouser(self,username,password):
        # 输入用户名
        self.driver.find_element(By.ID, "username").send_keys(username)
        # 输入密码
        self.driver.find_element(By.ID, "password").send_keys(password)

        # 点击登录
        self.driver.find_element(By.ID, "login_btn").click()



        result = self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div/form/div[1]/span[1]").text
        return result

    def loginNoPass(self,username,password):
        # 输入用户名

        self.driver.find_element(By.ID, "username").send_keys(username)
        # 输入密码

        self.driver.find_element(By.ID, "password").send_keys(password)

        # 点击登录

        self.driver.find_element(By.ID, "login_btn").click()
        sleep(1)


        result = self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div/form/div[2]/span[1]").text


        return result